<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="jquery-1.7.2.js"></script>
</head>
<body>
<table>
    <td class="rt_td">
        <input type="text">
        <a href="javascript:;" class="a-upload">
            <input type="file" class="up_btn" id="goods_photo_up">选择
        </a>
        <button class="rt_btn" id="goods_photo_btn">上传</button>
    </td>
</table>


<style>
    /*a  upload */
    .a-upload {
        padding: 4px 10px;
        height: 20px;
        line-height: 20px;
        position: relative;
        cursor: pointer;
        color: #888;
        background: #fafafa;
        border: 1px solid #ddd;
        border-radius: 4px;
        overflow: hidden;
        display: inline-block;
        *display: inline;
        *zoom: 1
    }

    .a-upload  input {
        position: absolute;
        font-size: 100px;
        right: 0;
        top: 0;
        opacity: 0;
        filter: alpha(opacity=0);
        cursor: pointer
    }

    .a-upload:hover {
        color: #444;
        background: #eee;
        border-color: #ccc;
        text-decoration: none
    }
</style>
<script>
    $(function(){
        //选择按钮样式修改后修复功能
        $(".a-upload").on("change","input[type='file']",function(){
            $this = $(this);
            var filePath=$(this).val();
            if(filePath.indexOf("jpg")!=-1 || filePath.indexOf("png")!=-1){
                var arr=filePath.split('\\');
                var fileName=arr[arr.length-1];
                $this.closest("td").find("input[type='text']").val(fileName);
            }else{
                //$this.closest("td").find("input[type='text']").html("");
                $this.closest("td").find("input[type='text']").html("您未上传文件，或者您上传文件类型有误！").show();
                return false
            }
        });
    });
</script>
</body>
</html>